<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编程导航评论管理</title>
    <link rel="stylesheet" href="./css/style.css">
    <!--引入vue相关的js文件-->
    <script src="./js/vue.js"></script>
    <script src="./js/axios.min.js"></script>
</head>
<body>
<div class="container" id="app">
    <h2>新增评论</h2>
    <form id="addCommentForm" action="javascript:void(0)">
        <!-- <div class="form-group">
             <label for="empId">用户编号</label>
             <input type="text" id="empId" name="empId" required>
         </div>-->
        <div class="form-group">
            <label for="paper_id">文章id</label>
            <input v-model="addCommentData.paper_id" type="text" id="paper_id" name="paper_id" required>
        </div>
        <div class="form-group">
            <label for="user_id">用户id</label>
            <input v-model="addCommentData.user_id" type="text" id="user_id" name="user_id" required>
        </div>
        <div class="form-group">
            <label for="publish_date">发布日期</label>
            <input v-model="addCommentData.publish_date" type="date" id="publish_date" name="publish_date" required>
        </div>
        <div class="form-group">
            <label for="like_count">点赞人数</label>
            <input v-model="addCommentData.like_count" type="text" id="like_count" name="like_count" required>
        </div>
        <div class="form-group">
            <label for="favorite_count">收藏人数</label>
            <input v-model="addCommentData.favorite_count" type="text" id="favorite_count" name="favorite_count" required>
        </div>
        <div class="form-group">
            <label for="content">评论内容</label>
            <input v-model="addCommentData.content" type="text" id="content" name="content"
                   required>
        </div>
        <button type="submit" @click="addComment">保存</button>
    </form>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            addCommentData: {
                paper_id: '',
                user_id: '',
                publish_date: '',
                like_count: '',
                favorite_count: '',
                content: ''
            }
        },
        methods: {
            addComment: function () {
                axios({
                    url: "/pns/addComment",
                    method: "get",
                    params: this.addCommentData
                }).then(result => {
                    let code = result.data.code;
                    if (code == "200") {
                        //重新查询
                        location.href = "/pns/comment.html";
                    } else {
                        //给出失败原因
                        alert(result.data.msg);
                    }
                });
            }
        }
    });
</script>
</body>
</html>